package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 检索范围，1：集团全体，2：本单位全体，3：指定范围，4：无
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum ArchiveAuthEnum {

  /** 目录 */
  GROUP_ALL(1, "集团全体", "groupAll"),
  /** 目录 */
  DEPT_ALL(2, "本单位全体", "deptAll"),
  WITH_SCOPE(3, "指定范围", "withScope"),
  NO_AUTH(4, "无", "noAuth"),
  ;

  private Integer code;
  private String desc;
  private String field;

  public static ArchiveAuthEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static ArchiveAuthEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
